package entitys

import (
	"time"

	"github.com/jinzhu/gorm"
)

type SysUser struct {
	Id            int32     `gorm:"primary_key" json:"userId"`
	LoginName     string    `json:"loginName"`
	Password      string    `json:"password"`
	Name          string    `json:"name"`
	Email         string    `json:"email"`
	Phone         string    `json:"phone"`
	Avatar        string    `json:"avatar"`
	Remark        string    `json:"remark"`
	IsEnable      int       `json:"isEnable"`
	IsDel         int       `json:"isDel"`
	LastLoginTime time.Time `json:"lastLoginTime"`
	Super         string    `json:"super"`
	Roles         []int32   `sql:"-" json:"roles"`
	EntityInfo    `gorm:"embedded"`
}

func (SysUser) TableName() string {
	return "sys_user"
}

func (sysUser *SysUser) BeforeCreate(scope *gorm.Scope) error {
	err := scope.SetColumn("CreaDtt", time.Now())
	err = scope.SetColumn("UptDtt", time.Now())
	return err
}

func (sysUser *SysUser) BeforeUpdate(scope *gorm.Scope) error {
	err := scope.SetColumn("UptDtt", time.Now())
	return err
}
